package algebra.query.pd;

import java.util.HashSet;
import java.util.Set;

import option.QueryKeywords;

import utils.Display;

import entities.role.Role;

public class PdFeature extends ProjDesc{

	private final Role f;
	
	public PdFeature(Role f){
		this.f = f;
	}
	
	public Role getFeature(){
		return f;
	}

	@Override
	public boolean projectOnSomeFeature() {
		return true;
	}

	@Override
	public Set<Role> extractFeatures() {
		Set<Role> fs = new HashSet<Role>();
		fs.add(f);
		return fs;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((f == null) ? 0 : f.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof PdFeature))
			return false;
		PdFeature other = (PdFeature) obj;
		if (f == null) {
			if (other.f != null)
				return false;
		} else if (!f.equals(other.f))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return this.f + Display.QUERYSYMBOL;
	}

	@Override
	public String toSerializedString() {
		return "(" + QueryKeywords.PD_FEATURE + " " + this.f + ")";
	}

	@Override
	public boolean moreSpecificThan(ProjDesc that) {
		if(that instanceof PdFeature){
			return this.f.equals(((PdFeature) that).f);
		}
		return false;
	}

	@Override
	public boolean hasConjunctiveFeature() {
		return true;
	}
	
	
}
